﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public class CheckRights : IHttpModule
{
    public CheckRights()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    void IHttpModule.Dispose()
    {

    }

    public void Init(HttpApplication context)
    {
        context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
    }

    void context_AcquireRequestState(object sender, EventArgs e)
    {
        //HttpApplication ha = sender as HttpApplication;
        //HttpContext hc = ha.Context;

        ////获取当前路径                        
        //string path1 = hc.Request.Path;
        //string path = path1.Substring(1);

        //if (path.IndexOf(".aspx") > 0)
        //{
        //    if (path.IndexOf("Default.aspx") < 0 && path.IndexOf("Main.aspx") < 0 && path.IndexOf("default.aspx")<0)
        //    {
        //        if (hc.Session["userRights"] == null)
        //        {
        //            hc.Response.Write("<script>alert('对不起，由于您长时间未操作，系统安全时间已过期，请重新登录！');top.location.href= '/Default.aspx '</script>");

        //            //hc.Response.Write();
        //        }
        //        else
        //        {
        //            List<int> li = hc.Session["userRights"] as List<int>;
        //            Dictionary<string, int> d = hc.Application["rights"] as Dictionary<string, int>;

        //            int a = d[path];
        //            try
        //            {
        //                if (li != null)
        //                {
        //                    if (!li.Contains(d[path]))
        //                    {
        //                        hc.Response.Redirect("~/NoRights.aspx");
        //                    }

        //                }
        //                else
        //                {
        //                    hc.Response.Redirect("~/Default.aspx");
        //                }

        //            }
        //            catch (Exception)
        //            {

        //                //hc.Response.Redirect("~/NoRights.aspx");
        //            }
        //        }

        //   }
        //}



    }

}
